using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint.Publishing.WebControls;
using System.Web.UI.WebControls;

namespace ARF.Web.Fields
{
    public class MultiLinkField : ARF.Web.Fields.BaseField
    {
        private int _maxLinks = 10;
        private Panel _links = null;
        private bool _useToolbar = true;

        public bool UseToolbar
        {
            get { return _useToolbar; }
            set { _useToolbar = value; }
        }

        public int MaxLinks
        {
            get { return _maxLinks; }
            set { _maxLinks = value; }
        }

        protected ToolBarButton _addLinkButton = null;

        protected override void CreateChildControls()
        {
            if (UseToolbar) AddToolBar();

            AddLinks();

            base.CreateChildControls();
        }

        protected virtual void AddLinks()
        {
            _links = new Panel();
            Controls.Add(_links);

            for (int i = 0; i < MaxLinks; i++)
            {
                RichLinkSelector oSelector = new RichLinkSelector();
                _links.Controls.Add(oSelector);
                oSelector.Visible = false;
            }
        }

        protected virtual void AddToolBar()
        {
            ToolBar oToolbar = AddToolbar(this);
            _addLinkButton = AddToolbarButton(oToolbar, "Add Link", "idAdd");
            _addLinkButton.Click += new EventHandler(addLinkButton_Click);
        }

        private void addLinkButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < MaxLinks; i++)
            {
                if ((_links.Controls[i] is RichLinkSelector) && !_links.Controls[i].Visible)
                {
                    _links.Controls[i].Visible = true;
                    return;
                }
            }
        }


    }
}
